package com.ruoyi.order.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.WxFormRecord;
import com.ruoyi.order.domain.WxFormRecordItem;
import com.ruoyi.order.service.IWxFormRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 记录表单数据Controller
 * 
 * @author ruoyi
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/merchant/record")
public class WxFormRecordController extends BaseController
{
    @Autowired
    private IWxFormRecordService wxFormRecordService;

    /**
     * 查询记录表单数据列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxFormRecord wxFormRecord)
    {
        startPage();
        List<WxFormRecord> list = wxFormRecordService.selectWxFormRecordList(wxFormRecord);
        return getDataTable(list);
    }

    /**
     * 导出记录表单数据列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:export')")
    @Log(title = "记录表单数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxFormRecord wxFormRecord)
    {
        List<WxFormRecord> list = wxFormRecordService.selectWxFormRecordList(wxFormRecord);
        ExcelUtil<WxFormRecord> util = new ExcelUtil<WxFormRecord>(WxFormRecord.class);
        util.exportExcel(response, list, "记录表单数据数据");
    }

    /**
     * 获取记录表单数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxFormRecordService.selectWxFormRecordById(id));
    }

    /**
     *  查询提成表单
     * @param wxFormRecord 查询的提成条件
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:query')")
    @PostMapping(value = "/commission")
    public AjaxResult getOrderFormInfo(@RequestBody WxFormRecord wxFormRecord)
    {
        return success(wxFormRecordService.selectWxFormRecordByOrderNum(wxFormRecord.getUid(),wxFormRecord.getOrderType(),wxFormRecord.getOrderNum()));
    }

    /**
     * 新增记录表单数据
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:add')")
    @Log(title = "记录表单数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxFormRecord wxFormRecord)
    {
        return toAjax(wxFormRecordService.insertWxFormRecord(wxFormRecord));
    }

    /**
     * 修改记录表单数据
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:edit')")
    @Log(title = "记录表单数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxFormRecord wxFormRecord)
    {
        return toAjax(wxFormRecordService.updateWxFormRecord(wxFormRecord));
    }

    @PreAuthorize("@ss.hasPermi('merchant:record:edit')")
    @Log(title = "记录表单数据", businessType = BusinessType.UPDATE)
    @PutMapping("editRecordItem")
    public AjaxResult editRecordItem(@RequestBody List<WxFormRecordItem> recordItemList)
    {
        return toAjax(wxFormRecordService.editRecordItem(recordItemList));
    }

    /**
     * 删除记录表单数据
     */
    @PreAuthorize("@ss.hasPermi('merchant:record:remove')")
    @Log(title = "记录表单数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxFormRecordService.deleteWxFormRecordByIds(ids));
    }


}
